

using System;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Windows.Forms;

using CStock;


namespace EForms
{
	/// <summary>
	/// Summary description for TreeNodeStock.
	/// </summary>
	public class TreeNodeStock : TreeNode,ITreeNode
	{
		#region fields
		
		//private IMainClass mainClass;

		private ITreeNode portfolioTreeNode;
		private ITreeNode shareTreeNode;
		
		#endregion

		#region Constructor
		
	
		private TreeNodeStock():base()
		{
			
		}
		private TreeNodeStock(string nodeName):base(nodeName)
		{
			
		}

		/// <summary>
		/// TreeNodeStock
		/// </summary>
		/// <param name="nodeName"></param>
		/// <param name="treeNodeInfo"></param>
		public TreeNodeStock(string nodeName,  TreeNodeInfo myTreeNodeInfo)
			:this(nodeName)
		{
            
            

			this.Tag = myTreeNodeInfo;
		}
		private TreeNodeStock(SerializationInfo info,StreamingContext context)
		{
			this.Text = info.GetString("text");
			this.Tag = info.GetValue("tag",typeof(TreeNodeStock));
		}
	

		#endregion

		#region interface ITreeNode

		/// <summary>
		/// TreeNodeInfo
		/// </summary>
		public ITreeNodeInfo TreeNodeInfo
		{
			get
			{
				return this.Tag as TreeNodeInfo;
			}
		}
		/// <summary>
		/// TreeNodeBase
		/// </summary>
		public string TreeNodeBase
		{
			get
			{
				ITreeNodeInfo treeNodeInfo = this.TreeNodeInfo;
				return treeNodeInfo.BaseType;
			}
		}
		/// <summary>
		/// TreeNodeData
		/// </summary>
		public object PortfolioOrDataItem
		{
			get
			{
				ITreeNodeInfo treeNodeInfo = this.TreeNodeInfo;
				return treeNodeInfo.PortfolioOrDataItem;
			}
		}
		/// <summary>
		/// PortfolioTreeNode
		/// </summary>
		/// <returns></returns>
		public ITreeNode PortfolioTreeNode
		{
			get
			{

				ITreeNodeInfo treeNodeInfo = this.TreeNodeInfo;
				switch (this.TreeNodeBase)
				{
					case EForms.TreeNodeInfo.PORTFOLIO:
					{
						return this;
					}
                    case EForms.TreeNodeInfo.SHARE:
                    case EForms.TreeNodeInfo.PARAMETER:
					{
						return this.portfolioTreeNode;
					}
					default:
					{
						throw new Exception("TreeNodeStock-TreeNodePortfolio-Unknown TreeNode Type");
					}
				}
			}
		}
		/// <summary>
		/// ShareTreeNode
		/// </summary>
		public ITreeNode ShareTreeNode
		{
			get
			{
				ITreeNodeInfo treeNodeInfo = this.TreeNodeInfo;
				switch (this.TreeNodeBase)
				{
                    case EForms.TreeNodeInfo.PORTFOLIO:
					{
						return null;
					}
                    case EForms.TreeNodeInfo.SHARE:
					{
						return this;
					}
                    case EForms.TreeNodeInfo.PARAMETER:
					{
						return this.shareTreeNode;
					}
					default:
					{
						throw new Exception("TreeNodeStock-TreeNodePortfolio-Unknown TreeNode Type");
					}
				}
			}
		}
		/// <summary>
		/// SetParentTreeNodes
		/// </summary>
		/// <param name="portfolioTreeNode"></param>
		/// <param name="shareTreeNode"></param>
		public void SetParentTreeNodes(ITreeNode portfolioTreeNode,ITreeNode shareTreeNode)
		{
			this.portfolioTreeNode = (TreeNodeStock)portfolioTreeNode;
			this.shareTreeNode = (TreeNodeStock)shareTreeNode;
		}

		#endregion

		#region Interface ISerializable
		
		public void SerializationData(SerializationInfo info,StreamingContext context)
		{
			//serialization
			info.AddValue("text",this.Text);
			info.AddValue("tag",this.Tag);
		}
		#endregion	



	}
}
